/*
 * Systemprogrammierung
 * Multiplayer-Quiz
 *
 * Gemeinsam verwendete Module
 *
 * rfc.h: Definitionen für das Netzwerkprotokoll
 */

#ifndef RFC_H
#define RFC_H

#include "common/question.h"
#include <stdint.h>

//Port für Netzwerkkommunikation festlegen
#define TCP_DEFAULT_PORT "54321"
#define TCP_DEFAULT_HOST "127.0.0.1"

//Fehlerdefinitionen
//RFC Errors
#define UNKNOWN_ERROR -1
#define SOCKET_ERROR -2
#define SEND_ERROR -3
#define RECEIVE_ERROR -4

//Header Definitionen
#define HEADER_LENGTH (3)
#define DATA_OFFSET (3)
#define MSG_TYPE_OFFSET (0)
#define MSG_TYPE_LENGTH (1)
#define MSG_LENGTH_OFFSET (1)
#define MSG_LENGTH_LENGTH (2)

struct NET_HEADER {
	uint8_t type; //Art der Nachricht
	uint16_t size; //Länge der nachfolgenden Zusatzdaten in Byte
};

//Payload Definition
struct NET_MESSAGE {
	struct NET_HEADER header; //common first data always is HEADER
	char* data;
};

//Nachrichtentypen
//LoginRequest
#define TYPE_IS_LOGIN_REQUEST (1)
#define MSG_NAME_OFFSET (13)

//Login Response ok
#define TYPE_IS_LOGIN_RESPONSE_OK (2)

//Catalog Request
#define TYPE_IS_CATALOG_REQUEST (3)

//Catalog Response
#define TYPE_IS_CATALOG_RESPONSE (4)

//Catalog Change
#define TYPE_IS_CATALOG_CHANGE (5)

//Player List
#define TYPE_IS_PLAYER_LIST (6)

//Start game
#define TYPE_IS_START_GAME (7)

//Question Request
#define TYPE_IS_QUESTION_REQUEST (8)

//Question
#define TYPE_IS_QUESTION (9)

//Question Answered
#define TYPE_IS_QUESTION_ANSWERED (10)

//Question Result
#define TYPE_IS_QUESTION_RESULT (11)

//Game over
#define TYPE_IS_GAME_OVER (12)

//Error
#define TYPE_IS_ERROR (255)
#define ERROR_IS_WARNING (0)
#define ERROR_IS_FATAL_ERROR (1)

#endif
